/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.expression;


import java.util.List;

import dex.compiler.model.base.Place;
import dex.compiler.model.type.TypeNode;


/**
 * A function literal, like <code>$foo(String,String)</code>.
 * Function literals evalute to a function type.
 */
public class LiteralFunction extends Expression {

	
	/**
	 * The name of the function being referenced.
	 */
	private String name;
	
	
	/**
	 * The types of the function's parameters.
	 */
	private List<TypeNode> types;
	
	
	/**
	 * Constructs a new function literal.
	 * 
	 * @param place  the place where the function literal originated
	 * @param name   the name of the function being reference
	 * @param types  the types of that function's parameters
	 */
	public LiteralFunction(Place place, String name, List<TypeNode> types) {
		super(place);
		if (name == null) {
			throw new IllegalArgumentException("name may not be null");
		}
		if (types == null) {
			throw new IllegalArgumentException("types may not be null");
		}
		this.name = name;
		this.types = types;
	}


	@Override
	public String toString() {
		return "$" + name + "(" + TypeNode.listToString(types) + ")";
	}

	
	/**
	 * Returns the name of the function being referenced.
	 * 
	 * @return  the name of the function being referenced
	 */
	public String getName() {
		return name;
	}
	
	
	/**
	 * Returns the parameter types of the function being referenced.
	 * 
	 * @return  the parameter types of the function being referenced
	 */
	public List<TypeNode> getParameterTypes() {
		return types;
	}

}
